package com.ruoyi.hyperledge.chaincode;

import com.ruoyi.hyperledge.dto.DataDTO;
import com.ruoyi.hyperledge.dto.FileDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SpringBootTest
public class test {

    @Autowired
    private Invokecode invokecode;

    @Test
    public void testAll() throws Exception {
//        testCreateData();
//        testUpdateData();
//        testDeleteData();
//        testCreateData();
//        testUpdateData();
//        testQueryCurrentHistory();
//        testQueryHistory();
//        testQueryAllDataHistory();
    }
    public void testCreateData() throws Exception{
        FileDTO fileDTO1 = new FileDTO()
                .setFileName("file1").setFilePath("path1")
                .setOperUser("admin1").setOperTime("time1").setOperType("create");
        FileDTO fileDTO2 = new FileDTO()
                .setFileName("file2").setFilePath("path2")
                .setOperUser("admin2").setOperTime("time2").setOperType("create");
        List<FileDTO> files =new ArrayList<>();
        files.add(fileDTO1);
        files.add(fileDTO2);
        Map<String,List<FileDTO>> stages =new HashMap<>();
        stages.put("00.20",files);
        DataDTO dataDTO = new DataDTO()
                .setDataName("name")
                .setStandardCode("ISO")
                .setRemark("remark")
                .setStages(stages);
        invokecode.createData(dataDTO);
    }
    public void testUpdateData() throws Exception{
        String dataName = "name";
        String stage = "00.20";
        String oldFileName = "file1";
        FileDTO newfile = new FileDTO()
                .setFileName("updatefile1")
                .setFilePath("path1")
                .setOperUser("user1")
                .setOperTime("time1");
        invokecode.updateData(dataName,stage,oldFileName,newfile);
    }
    public void testDeleteData() throws Exception{
        invokecode.deleteData("name");
    }
    public void testQueryCurrentHistory() throws Exception{
        System.out.println(invokecode.queryCurrentHistory("name"));
    }
    public void testQueryHistory() throws Exception{
        System.out.println(invokecode.queryHistory("name"));
    }
    public void testQueryAllDataHistory() throws Exception{
        System.out.println(invokecode.queryAllDataHistory());
    }
}
